package xhwl.insurance.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;

import xhwl.insurance.R;
import xhwl.insurance.http.bean.resp.SanJiFenXiaoResp;
import xhwl.insurance.util.ImgTools;

/**
 * Created by chengang on 2017/6/7.
 */

public class ResultsEndorsementAdapter extends BaseAdapter {

    private ArrayList<SanJiFenXiaoResp> mlist;
    private Context mContext;

    public ResultsEndorsementAdapter(Context mContext, ArrayList<SanJiFenXiaoResp> mlist) {

        this.mContext = mContext;
        this.mlist = mlist;
    }

    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int position) {
        return mlist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.results_endorsement_item, null);
            holder = new ViewHolder();
            holder.tv_patientname = (TextView) convertView.findViewById(R.id.sanjifenxiao_nickname);
            holder.tv_context = (TextView) convertView.findViewById(R.id.sanjifenxiao_membername);
            holder.tv_waitreply = (TextView) convertView.findViewById(R.id.sanjifenxiao_status);
            holder.tv_patientconsult_date = (TextView) convertView.findViewById(R.id.sanjifenxiao_phone);
            holder.sanjifenxiao_personname = (TextView) convertView.findViewById(R.id.sanjifenxiao_personname);
            holder.patientconsult_img = (ImageView) convertView.findViewById(R.id.sanjifenxiao_img);
            holder.sanjifenxiao_psstatus = (TextView) convertView.findViewById(R.id.sanjifenxiao_psstatus);
            holder.sanjifenxiao_buytype = (TextView) convertView.findViewById(R.id.sanjifenxiao_buytype);
            holder.sanjifenxiao_wlnumber = (TextView) convertView.findViewById(R.id.sanjifenxiao_wlnumber);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (mlist.get(position).getORDER_STATUS().equals("已付款")) {
            holder.tv_waitreply.setTextColor(mContext.getResources().getColor(R.color.green));
        } else {
            holder.tv_waitreply.setTextColor(mContext.getResources().getColor(R.color.orange));

        }

        ImgTools.getInstance().getRadiusImgFromNetByUrl(mlist.get(position).getHEADIMGURL(), holder.patientconsult_img, R.drawable.touxiang, 90);
        holder.tv_patientname.setText(mlist.get(position).getNICKNAME());
        holder.tv_context.setText(mlist.get(position).MEMBER_NAME);
        holder.tv_patientconsult_date.setText("保障人手机号: " + mlist.get(position).getPERSON_MOBILE());
        holder.tv_waitreply.setText(mlist.get(position).getORDER_STATUS());
        holder.sanjifenxiao_personname.setText("保障人姓名: " + mlist.get(position).getPERSON_NAME());
        if (mlist.get(position).getORDER_STATUS().equals("已付款")) {
            if ("自提".equals(mlist.get(position).getZT_FLAG())) {
                holder.sanjifenxiao_wlnumber.setVisibility(View.GONE);
                holder.sanjifenxiao_psstatus.setText("自提");
//                holder.sanjifenxiao_wlnumber.setText("物流编号: " + "暂无");
            } else {
                String fhzt = "未发货";
                String code = !"0".equals(mlist.get(position).getWL_CODE()) ? mlist.get(position).getWL_CODE() : "暂无";
                if (!"0".equals(mlist.get(position).getWL_CODE())) {
                    holder.sanjifenxiao_psstatus.setText("已发货");
                } else {
                    holder.sanjifenxiao_psstatus.setText(fhzt);
                }
                holder.sanjifenxiao_wlnumber.setVisibility(View.VISIBLE);
                holder.sanjifenxiao_wlnumber.setText("物流编号: " + code);
            }
        } else {
            if ("自提".equals(mlist.get(position).getZT_FLAG()))
                holder.sanjifenxiao_wlnumber.setVisibility(View.GONE);
            holder.sanjifenxiao_psstatus.setText("未发货");
            holder.sanjifenxiao_wlnumber.setText("物流编号: " + "暂无");
        }

        holder.sanjifenxiao_buytype.setText("购买类型: " + mlist.get(position).getSALE_TYPE());
        return convertView;
    }

    class ViewHolder {
        TextView tv_patientname;
        TextView tv_context;
        TextView tv_waitreply;
        TextView tv_patientconsult_date;
        ImageView patientconsult_img;
        TextView sanjifenxiao_personname;
        TextView sanjifenxiao_psstatus;
        TextView sanjifenxiao_buytype;
        TextView sanjifenxiao_wlnumber;

    }
}
